package top.lvjp.designMode;

/** 创建接口 */
interface Shape {
    void draw();
}

/** 创建实现接口的实体类 */
class Rectangle implements Shape{
    @Override
    public void draw(){
        System.out.println("---Rectangle---");
    }
}
class Circle implements Shape {
    @Override
    public void draw() {
        System.out.println("---Circle---");
    }
}

/** 创建工厂 */
class ShapeFactory{
    public static Shape getRectangle(){
        return new Rectangle();
    }
    public static Shape getCircle(){
        return new Circle();
    }
}

/** 使用工厂 */
public class FactoryTest {
    public static void main(String[] args) {
        Shape shape = ShapeFactory.getRectangle();      //获取rectangle对象
        shape.draw();
        shape = ShapeFactory.getCircle();            //获取circle对象
        shape.draw();
    }
}
